import copy
import json
import os

CONFIG = None


def get_config():
    base = os.path.abspath(os.path.dirname(__file__))
    global CONFIG
    if CONFIG:
        return CONFIG

    env = "dev"
    with open(os.path.join(base, "config.json")) as f:
        config = json.load(f)
    if os.environ.get("DEPLOY_ENV"):
        env = os.environ.get("DEPLOY_ENV")
    print("ENV:", env)
    config[env].update({
        "app_name": config["app_name"],
        "default_log_dir": os.path.join(base, "logs")
        })
    CONFIG = copy.deepcopy(config[env])
    return CONFIG
